package cre.sample.test.bigdata;

/**
 * @Author penglai
 * @Date 2016/9/28.
 */
public class Page {
    private int totalCount;
    private int totalPage;
    private int pageNo;
    private int pageSize;
    private int mod;

    public Page(int totalCount, int totalPage) {
        this.totalCount = totalCount;
        this.totalPage = totalPage;
        cut();
    }

    private void cut() {
        mod = totalCount % totalPage;
        pageSize = totalCount / totalPage;

    }

    public int startIndex(int pageNo) {
        return (pageNo * pageSize);
    }

    public int endIndex(int pageNo) {
        if (pageNo < totalPage - 1) {
            return (pageNo + 1) * pageSize - 1;
        }
        return totalCount - 1;
    }

    public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }

    public int getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public int getPageNo() {
        return pageNo;
    }

    public void setPageNo(int pageNo) {
        this.pageNo = pageNo;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getMod() {
        return mod;
    }

    public void setMod(int mod) {
        this.mod = mod;
    }
}
